﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BeIT.MemCached;

namespace cmsservice.Common.Memcached
{
    public class FTStockMemcachedTools : IMemcachedCache
    {
        static string cacheName = Guid.NewGuid().ToString();
        static FTStockMemcachedTools()
        {
            String[] serverlist = System.Configuration.ConfigurationManager.AppSettings["FTStockHq"].Split('|');
            MemcachedClient.Setup(cacheName, serverlist);
            MemcachedClient cache = MemcachedClient.GetInstance(cacheName);
            cache.SendReceiveTimeout = 5000;
            cache.ConnectTimeout = 5000;
            cache.MinPoolSize = 1;
            cache.MaxPoolSize = 5;
        }

        public object GetClient()
        {
            return MemcachedClient.GetInstance(cacheName);
        }

        public void Add(string key, object obj, int hours, int minutes, int seconds)
        {
            throw new NotImplementedException();
        }

        public void Remove(string key)
        {
            throw new NotImplementedException();
        }

        public void FlushAll()
        {
            throw new NotImplementedException();
        }

        public T Get<T>(string key)
        {
            MemcachedClient cache = (MemcachedClient)GetClient();
            return (T)cache.Get(key);
        }
    }
}
